<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class NoticeEvent implements ShouldBroadcastNow
{
    use Dispatchable;


    public $user_id;

    public function __construct(string $user_id)
    {
        $this->user_id = $user_id;
    }

    /**
     * 事件的名称
     */
    public function broadcastAs(): string
    {
        return 'notice.event';
    }

    public function broadcastOn(): array
    {
        return [
            new PrivateChannel("notice.{$this->user_id}"),
        ];
    }

    // 发送前端的数据信息
    public function broadcastWith()
    {
        return [
            'id' => $this->user_id
        ];
    }
}
